package com.lyl.pipeline.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;

/**
 * @author 97134
 */
public class ContextHolderUtils {
	private ContextHolderUtils() {
	}

	public static HttpServletRequest getRequest() {
		ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		return Objects.nonNull(requestAttributes) ? requestAttributes.getRequest() : null;
 	}

	public static HttpServletResponse getResponse(){
		ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		return Objects.nonNull(requestAttributes) ? requestAttributes.getResponse() : null;
	}
}
